package com.dfbz;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dfbz.entity.User;
import com.dfbz.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
@SpringBootTest(classes = MyBatisPlusApplication.class)
@RunWith(SpringRunner.class)
public class Demo07_LambdaUpdateMapper {

    @Autowired
    private UserMapper userMapper;

    /**
     * 使用UpdateWrapper
     *
     * @throws Exception
     */
    @Test
    public void test1() throws Exception {

        UpdateWrapper<User> wrapper = Wrappers.update();
        wrapper.eq("id", "1");
        wrapper.set("name", "xiaohui");
        wrapper.set("age", 20);

        userMapper.update(null, wrapper);
    }

    /**
     * 使用LambdaUpdateWrapper
     *
     * @throws Exception
     */
    @Test
    public void test2() throws Exception {

        LambdaUpdateWrapper<User> wrapper = Wrappers.lambdaUpdate();

        wrapper.eq(User::getId,"1");
        wrapper.set(User::getName,"xiaolan");
        wrapper.set(User::getAge,18);

        userMapper.update(null,wrapper);
    }
}
